package com.totsp.conference;

import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;

import com.totsp.conference.data.Presentation;
import com.totsp.conference.data.Speaker;

import java.util.ArrayList;

public class DevNexusApp extends Application {

   private ConnectivityManager cMgr;
 
   private ArrayList<Speaker> speakersCache;
   private ArrayList<Presentation> presentationsCache;

   public DevNexusApp() {
      this.speakersCache = new ArrayList<Speaker>();
      this.presentationsCache = new ArrayList<Presentation>();
   }   
   
   public ArrayList<Speaker> getSpeakersCache() {
      return this.speakersCache;
   }

   public void setSpeakersCache(ArrayList<Speaker> speakersCache) {
      this.speakersCache = speakersCache;
   }
   
   public ArrayList<Presentation> getPresentationsCache() {
      return this.presentationsCache;
   }

   public void setPresentationsCache(ArrayList<Presentation> presentationsCache) {
      this.presentationsCache = presentationsCache;
   }

   //
   // lifecycle
   //
   @Override
   public void onCreate() {
      super.onCreate();
      cMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
   }

   @Override
   public void onTerminate() {
      // not guaranteed to be called
      super.onTerminate();
   }

   //
   // util/helpers for app
   //
   public boolean connectionPresent() {
      NetworkInfo netInfo = cMgr.getActiveNetworkInfo();
      if ((netInfo != null) && (netInfo.getState() != null)) {
         return netInfo.getState().equals(State.CONNECTED);
      }
      return false;
   }
}